<template>
  <div class="panel-container">
    <div class="panel-content">
      <div class="panel-line space-between">
        <div class="panel-title">中废通资讯</div>
        <el-button type="text" style="padding: 0" @click="handleMoreClick">更多>></el-button>
      </div>
      <div class="list">
        <div class="item" v-for="item in dataList" :key="item.ID" @click="handleClick(item)">
          <div class="title">{{ item.Title }}</div>
          <div class="time">{{ sliceTime(item.AddTime) }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { apiInfoHomepage } from '@/api/index'

export default {
  name: 'ZFTInformation',

  data() {
    return {
      dataList: {},
    }
  },
  watch: {},
  mounted() {
    this.getData()
  },
  destroyed() {},
  methods: {
    getData() {
      apiInfoHomepage({ pageNumber: 1, pageSize: 20 }).then((res) => {
        const { info } = res
        this.dataList = info
      })
    },
    handleMoreClick() {
      this.$store.dispatch('permission/routeAuthorization', 'Infomation').then((res) => {
        this.$bus.$emit('forceUpdate', 'Infomation')
        this.$router.push({
          path: '/infomation',
        })
      })
    },
    handleClick(item) {
      this.$store.dispatch('permission/routeAuthorization', 'InfomationDetail').then((res) => {
        localStorage.setItem('InfomationDetail', JSON.stringify(item))
        this.$bus.$emit('forceUpdate', 'InfomationDetail')
        this.$router.push({
          path: '/infomationDetail',
          query: {
            id: item.ID,
          },
        })
      })
    },
    sliceTime(time) {
      let result = ''
      if (time) {
        let sTime = time.slice(0, 10)
        if (sTime) {
          result = sTime.replaceAll('-', '/')
        }
      }
      return result
    },
  },
}
</script>

<style scoped lang="scss">
.panel-container {
  min-height: 90vh;
}
.panel-line {
  align-items: flex-start;
}
.list {
  width: 100%;
  font-size: 12px;
  line-height: 40px;
  color: #666666;
  .item {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    &:hover {
      color: #5db42c;
    }
    .title {
      width: calc(100% - 60px);
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .time {
      width: 60px;
    }
  }
}
</style>
